<?php

      define('install',1);
      include('../common.php');

echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="ar" dir="rtl">
<head>

<style type="text/css">
body { background-color: #EBEBEB; margin: 0px 0px 0px 0px;}
</style>

  <title>مرحباً بك في ملف تركيب برنامج  MySmartBB 1.7.0</title>
  <link rel="stylesheet" href="style.css" type="text/css" />
  <meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
</head>

<body>
<div align="center">
  <table border="0" cellspacing="1" class="border" summary="الهيدر" width="100%">
    <tr>
      <td width="100%" colspan="7" style="background: url(theme/header_bg.gif) repeat-x ;height:118px;"><img alt="{$board_title}" border="0" src="theme/logo.gif" height="118" /></td>
    </tr>
    <tr>
      <td class="tcat">معالج تركيب برنامج المنتدى العربي MySmartBB 1.7.0</td>
    </tr>
  </table>

  <br />

  <div align="center">
  <table class="border" summary="المحتويات" border="0" cellpadding="0" cellspacing="1" width="98%">
    <tr>
      <td class="context">

                <br />';

    $info_query = $DB->sql_query("SELECT * FROM MySBB_info WHERE id='1'");
    $info_row   = $DB->sql_fetch_array($info_query);

    if (empty($_GET['step'])) { $step = 1; }


    if ($step == 1)
    {
              if ($info_row['MySBB_version'] != "1.1.2")
              {
                     $SF->error('يجب ان يكون الاصدار 1.1.2 لكي يتم تحديثه');
            }

             $update = $DB->sql_query("UPDATE MySBB_info SET MySBB_version='1.1.3'");

             $query = array(
                                             "ALTER TABLE `MySBB_info` ADD `contactus_forvisitors` TINYINT( 2 ) NOT NULL" ,
                                                "ALTER TABLE `MySBB_info` ADD `contactus_titles` TEXT NOT NULL" ,
                                                "ALTER TABLE `MySBB_info` ADD `contactus_method` TINYINT( 4 ) NOT NULL" ,
                                                "ALTER TABLE `MySBB_info` ADD `contactus_link` VARCHAR( 255 ) NOT NULL" ,
                                                "ALTER TABLE `MySBB_info` ADD `contactus_email` VARCHAR( 255 ) NOT NULL" ,
                                                "ALTER TABLE `MySBB_info` ADD `contactus_active` INT( 1 ) NOT NULL" ,
                                                "ALTER TABLE `MySBB_info` ADD `contactus_perpage` INT( 2 ) NOT NULL" ,
                                                "ALTER TABLE `MySBB_info` ADD `contactus_attachactive` INT( 1 ) NOT NULL" ,
                                                "ALTER TABLE `MySBB_info` ADD `contactus_sig` TEXT NOT NULL",
                                                "ALTER TABLE `MySBB_member` ADD `unread_pm` INT( 9 ) NOT NULL",
                                                "ALTER TABLE `MySBB_info` ADD `ads_num` INT( 9 ) NOT NULL",
                                                "ALTER TABLE `MySBB_subject` ADD `lastreply_cache` TEXT NOT NULL",
                                                "ALTER TABLE `MySBB_subject` ADD `last_replier` VARCHAR( 255 ) NOT NULL",
                                                "ALTER TABLE `MySBB_subject` ADD `lastreply_date` VARCHAR( 10 ) NOT NULL",
                                                "ALTER TABLE `MySBB_sectionadmin` ADD `username` VARCHAR( 255 ) NOT NULL",
                                                "ALTER TABLE `MySBB_subject` ADD `poll_subject` INT( 1 ) NOT NULL",
                                                "ALTER TABLE `MySBB_info` ADD `smiles_cache` TEXT NOT NULL",
                                                "ALTER TABLE `MySBB_subject` ADD `attach_subject` INT( 1 ) NOT NULL",
                                                "ALTER TABLE `MySBB_reply` ADD `attach_reply` INT( 1 ) NOT NULL",
                                                "ALTER TABLE `MySBB_info` ADD `forums_cache` text NOT NULL",
                                                "ALTER TABLE `MySBB_info` ADD `sectiongroup_cache` text NOT NULL",
                                                  "ALTER TABLE `MySBB_info` ADD `subforums_cache` text NOT NULL",
                                                  "ALTER TABLE `MySBB_info` ADD `subject_number` int(9) NOT NULL default '0'",
                                                  "ALTER TABLE `MySBB_info` ADD `reply_number` int(9) NOT NULL default '0'",
                                                  "ALTER TABLE `MySBB_info` ADD `member_number` int(9) NOT NULL default '0'",
                                                  "ALTER TABLE `MySBB_info` ADD `last_member` varchar(255) NOT NULL default ''",
                                                  "ALTER TABLE `MySBB_info` ADD `last_member_id` int(9) NOT NULL default '0'",
                                              );

             foreach ($query as $key => $value)
             {
                     $query = $DB->sql_query($value);

            if ($query)
                {
                               $SF->msg("تمت العمليه #" . $key . " من اصل " . count($query) . " عمليه");
                      }
             }

                $getsectionadmin_query = $DB->sql_query("SELECT * FROM MySBB_sectionadmin");
                while ($getsa_row = $DB->sql_fetch_array($getsectionadmin_query))
                {
                        $getuname_query = $DB->sql_query("SELECT * FROM MySBB_member WHERE id='" . $getsa_row['member_id'] . "'");


                        while ($getuname_row = $DB->sql_fetch_array($getuname_query))
                        {
                                $update = $DB->sql_query("UPDATE MySBB_sectionadmin SET username='" . $SF->SafeSQL($getuname_row['username']) . "' WHERE id='" . $getsa_row['id'] . "'");
                        }

                        if ($update)
                        {
                                $SF->msg('تم تعيين اسم المدير ' . $getsa_row['id']);
                        }
                }

                $forums = $SF->UpdateForumsArray();
                if ($forums)
                {
                        $SF->msg('تم انشاء مصفوفة الاقسام بنجاح');
                }

                $groups = $SF->UpdateSectionGroupArray();
                if ($groups)
                {
                        $SF->msg('تم انشاء مصفوفة المجموعات بنجاح');
                }

                $subs = $SF->UpdateSubForums();
                if ($subs)
                {
                        $SF->msg('تم انشاء مصفوفة الاقسام الفرعيه بنجاح');
                }

                $reply = $SF->UpdateLastReplyArray();
                if ($reply)
                {
                        $SF->msg('تم انشاء مصفوفة آخر رد بنجاح');
                }

                $smile = $SF->UpdateSmileArray();
                if ($smile)
                {
                        $SF->msg('تم انشاء مصفوفة الابتسامات بنجاح');
                }

                $SF->install_msg('<br /><div align="center"><input type="submit" onclick="location.href=\'?step=2\'" value="الخطوه التاليه" name="B1" /></div>');
        }

        if ($_GET['step'] == 2)
        {
                $getug_query = $DB->sql_query("SELECT * FROM MySBB_membergroup");
                while ($ug_row = $DB->sql_fetch_array($getug_query))
                {
                        $update = $DB->sql_query("UPDATE MySBB_member SET usergroup='" . $ug_row['group_id'] . "' WHERE id='" . $ug_row['member_id'] . "'");

                        if ($update)
                        {
                                $SF->msg('تم تعيين مجموعه ' . $ug_row['member_id']);
                        }
                        else
                        {
                                $SF->msg('لم يتم تعيين مجموعه ' . $ug_row['member_id']);
                        }
                }

                ////////

                $ads_query         = $DB->sql_query("SELECT * FROM MySBB_ads");
                $ads_num        = $DB->sql_num_rows($ads_query);
                $ads_update = $DB->sql_query("UPDATE MySBB_info SET ads_num='" . $ads_num . "'");

                if ($ads_update)
                {
                        $SF->msg('تم تعيين عدد الاعلانات');
                }

                $getcu_query         = $DB->sql_query("SELECT * FROM MySBB_contactus_settings");
                $cu_row                 = $DB->sql_fetch_array($getcu_query);
                $cu_update                 = $DB->sql_query("UPDATE MySBB_info SET contactus_forvisitors='" . $cu_row['forvisitors'] . "',contactus_titles='" . $cu_row['titles'] . "',contactus_method='" . $cu_row['method'] . "',contactus_link='" . $cu_row['link'] . "',contactus_email='" . $cu_row['email'] . "',contactus_active='" . $cu_row['active'] . "',contactus_perpage='" . $cu_row['perpage'] . "',contactus_attachactive='" . $cu_row['attachactive'] . "',contactus_sig='" . $cu_row['sig'] . "' WHERE id='1'");

                if ($cu_update)
                {
                        $SF->msg('تم تعيين معلومات اتصل بنا');
                }
                $SF->install_msg('<br /><div align="center"><input type="submit" onclick="location.href=\'?step=3\'" value="الخطوه التاليه" name="B1" /></div>');
        }

        if ($_GET['step'] == 3)
        {
                $getsubjects = $DB->sql_query("SELECT * FROM MySBB_subject");
                while ($subject_row = $DB->sql_fetch_array($getsubjects))
                {
                        $getreply = $DB->sql_query("SELECT * FROM MySBB_reply WHERE subject_id='" . $subject_row['id'] . "'");
                        $replynum = $DB->sql_num_rows($getreply);

                        if ($replynum != 0)
                        {
                                $LastReplyArray = '$LastReply[] = array(';

                                while ($reply_row = $DB->sql_fetch_array($getreply))
                                {
                                        $LastReplyArray .= '[q]' . $SF->SafeSQL($reply_row['writer']) . '[q],';
                                }

                                $LastReplyArray .= '0);
                                ';

                                $LastReplyArray = str_replace('[q]',"'",$LastReplyArray);

                                $update = $DB->sql_query("UPDATE MySBB_subject SET lastreply_cache='" . addslashes($LastReplyArray) . "' WHERE id='" . $subject_row['id'] . "'");
                        }

                        $getlast = $DB->sql_query("SELECT * FROM MySBB_reply WHERE subject_id='" . $subject_row['id'] . "' ORDER BY id DESC LIMIT 1");
                        $lastrow = $DB->sql_fetch_array($getlast);

                        $update_list = $DB->sql_query("UPDATE MySBB_subject SET last_replier='" . $lastrow['writer'] . "',lastreply_date='" . $lastrow['write_date'] . "' WHERE id='" . $subject_row['id'] . "'");
                }

                $poll_query = $DB->sql_query("SELECT * FROM MySBB_poll");
                while ($poll_row = $DB->sql_fetch_array($poll_query))
                {
                        $update = $DB->sql_query("UPDATE MySBB_subject SET poll_subject='1' WHERE id='" . $poll_row['subject_id'] . "'");

                        if ($update)
                        {
                                $SF->msg('تم تعيين التصويت ' . $poll_row['subject_id']);
                        }
                }

                $attach_query = $DB->sql_query("SELECT * FROM MySBB_attach WHERE reply<>'1'");
                while ($attach_row = $DB->sql_fetch_array($attach_query))
                {
                        $update = $DB->sql_query("UPDATE MySBB_subject SET attach_subject='1' WHERE id='" . $attach_row['subject_id'] . "'");

                        if ($update)
                        {
                                $SF->msg('تم تعيين المرفق ' . $attach_row['subject_id']);
                        }
                }

                $attach_query = $DB->sql_query("SELECT * FROM MySBB_attach WHERE reply='1'");
                while ($attach_row = $DB->sql_fetch_array($attach_query))
                {
                        $update = $DB->sql_query("UPDATE MySBB_reply SET attach_reply='1' WHERE id='" . $attach_row['subject_id'] . "'");

                        if ($update)
                        {
                                $SF->msg('تم تعيين المرفق ' . $attach_row['subject_id']);
                        }
                }

                $member_num = $DB->sql_num_rows($DB->sql_query("SELECT * FROM MySBB_member"));
                $lastmember_query = $DB->sql_query("SELECT * FROM MySBB_member ORDER BY id DESC LIMIT 1");
                $lastmember_row   = $DB->sql_fetch_array($lastmember_query);

        $update_lastmember = $DB->sql_query("UPDATE MySBB_info SET last_member='" . $SF->SafeSQL($lastmember_row['username']) . "',last_member_id='" . $lastmember_row['id'] . "',member_number='" . $member_num . "' WHERE id='1'");

        if ($update_lastmember)
        {
                $SF->msg('تم ضبط العدادات #1');
        }

        $subject_num = $DB->sql_num_rows($DB->sql_query("SELECT * FROM MySBB_subject WHERE delete_topic<>'1'"));
        $reply_num = $DB->sql_num_rows($DB->sql_query("SELECT * FROM MySBB_reply WHERE delete_topic<>'1'"));

        $update_srnum = $DB->sql_query("UPDATE MySBB_info SET subject_number='" . $subject_num . "',reply_number='" . $reply_num . "'");

        if ($update_srnum)
        {
                $SF->msg('تم ضبط العدادات #2');
        }



             $SF->html('<br /><br />');

             if ($update)
             {
                     $SF->msg("تم بفضل الله تعالى التحديث إلى الاصدار 1.1.3");
                      $SF->msg("MySmartBB : نظره واثقه نحو المستقبل");
                      $SF->msg("http://www.MySmartBB.com");
                      $SF->html('<br /><div align="center"><input type="submit" onclick="location.href=\'update1.5.0.php\'" value="إكمال الترقية للإصدار الموالي " name="B1" /></div>');
             }
    }

echo'<br />

        </td>
  </tr>
  <tr>
    <td class="footer">هذا المنتدى يعمل على برنامج <a href="http://www.mysmartbb.com">MySmartBB</a> | إعداد وبرمجة فريق MySmartBB
    </td>
  </tr>
</table>
</div>
</div>
</body>
</html>';
?>